<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="include/common-header :: common_header(~{::title},~{::link})">
    <title>预约总规则</title>
</head>
<body class="gray-bg">

<!--页面内容开始-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>规则列表 </h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="table-responsive col-md-12">
                            <div class="m-l-xs toolbar">
                                <button class="btn btn-sm btn-primary" type="button"
                                        onclick="appointimeruleListObj.addOrUpdateHandle()"><i
                                        class="fa fa-plus"></i>&nbsp;新增
                                </button>
                                <button id="appointimeruleList_delAll" class="btn btn-sm btn-danger" type="button"
                                        disabled="disabled"
                                        onclick="appointimeruleListObj.deleteHandle()"><i
                                        class="fa fa-trash"></i>&nbsp;批量删除
                                </button>
                            </div>
                            <table id="appointimeruleList_table" class="table table-striped"></table>
                        </div>
                        <!--<div class="col-md-3">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    工作时间
                                </div>
                                <div class="panel-body">
                                    <p>昨晚上坐出租车，刚走一会儿发现前面一美女拦车，司机马上减速。我心想和美女坐一起也不错。。。
                                        结果师傅说：你下车吧，不收你钱。。。</p>
                                </div>

                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    例外设置
                                </div>
                                <div class="panel-body">
                                    <p>昨晚上坐出租车，刚走一会儿发现前面一美女拦车，司机马上减速。我心想和美女坐一起也不错。。。
                                        结果师傅说：你下车吧，不收你钱。。。</p>
                                </div>

                            </div>
                        </div>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--页面内容结束-->
<div th:replace="include/common-js :: common_js"></div>
<!--弹窗：编辑-->
<div th:replace="web/appoin/appointimerule-add-or-update::appointimeruleAddOrUpdate"></div>
<!--弹窗：工作时间-->
<div th:replace="web/appoin/appointimerule-week::appointimeruleWeek"></div>
<!--弹窗：例外设置-->
<div th:replace="web/appoin/appointimerule-special::appointimeruleSpecial"></div>
<script type="text/javascript">
    $().ready(function () {
        appointimeruleListObj.initTable();
    })
    var appointimeruleListObj = new Object({
        dataListSelections: [],
        myTable: undefined,
        addOrUpdateHandle: function (id) {
            appointimeruleAddOrUpdateObj.init(id);
            $('#appointimeruleAddOrUpdate_Modal').modal('show')
        },
        deleteHandle: function (id) {
            let ids = id ? [id] :
                this.dataListSelections.map(item => {
                    return item.id;
                });
            let tipMsg = id ? '删除' : '批量删除';
            $.mySwalConfirm(`将${tipMsg}，确认吗？`, function () {
                $.myPost({
                    url: `/appoin/appointimerule/delete`,
                    dataType: "json",
                    data: ids,
                    success: function (data) {
                        if (data && data.code === 0) {
                            toastr.success(data.msg, '操作提示')
                            appointimeruleListObj.refreshDataList();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            });
        },
        workHandle: function (id) {
            appointimeruleWeekObj.init(id);
        },
        specialHandle: function (id) {
            appointimeruleSpecialObj.init(id);
        },
        playHandle: function (id) {
            $.mySwalConfirm('将启动新规则，确认吗？', function () {
                $.myPost({
                    url: `/appoin/appointimerule/state/${id}`,
                    success: function (data) {
                        if (data && data.code === 0) {
                            toastr.success(data.msg, '操作提示')
                            appointimeruleListObj.refreshDataList();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            });
        },
        checkRowHander: function () {
            appointimeruleListObj.dataListSelections = appointimeruleListObj.myTable.bootstrapTable('getSelections');
            if (appointimeruleListObj.dataListSelections.length > 0) {
                $('#appointimeruleList_delAll').removeAttr("disabled");
            } else {
                $('#appointimeruleList_delAll').attr("disabled", "disabled");
            }
        },
        refreshDataList: function () {
            appointimeruleListObj.myTable.bootstrapTable('refresh');
        },
        initTable: function () {
            appointimeruleListObj.myTable = $('#appointimeruleList_table').bootstrapTable({
                toolbar: ".toolbar",
                //cardView: true,
                pagination: true,
                sidePagination: 'server',
                url: '/appoin/appointimerule/list',
                queryParamsType: '',
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                queryParams: function (param) {
                    return param;
                },
                onCheck: function (row, $element) {
                    appointimeruleListObj.checkRowHander();
                },
                onUncheck: function (row, $element) {
                    appointimeruleListObj.checkRowHander();
                },
                onCheckAll: function (row, $element) {
                    appointimeruleListObj.checkRowHander();
                },
                onUncheckAll: function (row, $element) {
                    appointimeruleListObj.checkRowHander();
                },
                onCheckSome: function (row) {
                    appointimeruleListObj.checkRowHander();
                },
                onUncheckSome: function (row) {
                    appointimeruleListObj.checkRowHander();
                },
                columns: [{
                    title: '#',
                    align: 'center',
                    width: 50,
                    checkbox: true,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                }, {
                    title: '标题',
                    field: 'title'
                }, {
                    title: '工作角色',
                    field: 'workerRoleName'
                }, {
                    title: '工作时间间隔（分钟）',
                    field: 'interval'
                }, {
                    title: '自动生成天数',
                    field: 'activeDay'
                }, {
                    title: '自动生成工作时间',
                    field: 'isAuto',
                    formatter: function (value, row, index) {
                        return value ? "是" : "否";
                    }
                }, {
                    title: '创建时间',
                    field: 'createTime'
                }, {
                    title: '是否启用',
                    field: 'isActive',
                    formatter: function (value, row, index) {
                        return value ? "启用" : "";
                    }
                }, {
                    title: '操作',
                    width: 240,
                    events: {
                        'click .edit': function (e, value, row, index) {
                            appointimeruleListObj.addOrUpdateHandle(row.id)
                        },
                        'click .trash': function (e, value, row, index) {
                            appointimeruleListObj.deleteHandle(row.id)
                        },
                        'click .work': function (e, value, row, index) {
                            appointimeruleListObj.workHandle(row.id)
                        },
                        'click .special': function (e, value, row, index) {
                            appointimeruleListObj.specialHandle(row.id)
                        },
                        'click .play': function (e, value, row, index) {
                            appointimeruleListObj.playHandle(row.id)
                        }
                    },
                    formatter: function (value, row, index) {
                        var opers = [];
                        opers.push(`<a class="edit btn btn-white btn-bitbucket text-success" data-toggle="tooltip" data-placement="top" title="编辑">
                                    <i class="fa fa-edit"></i>
                                </a>`)
                        opers.push(`<a class="work btn btn-white btn-bitbucket text-success" data-toggle="tooltip" data-placement="top" title="工作时间">
                                    <i class="fa fa-clock-o"></i>
                                </a>`)
                        opers.push(`<a class="special btn btn-white btn-bitbucket text-success" data-toggle="tooltip" data-placement="top" title="例外设置">
                                    <i class="fa fa-puzzle-piece"></i>
                                </a>`)
                        if (!row.isActive) {
                            opers.push(`<a class="play btn btn-white btn-bitbucket text-success" data-toggle="tooltip" data-placement="top" title="启用">
                                    <i class="fa fa-play"></i>
                                </a>`)
                            opers.push(`<a class="trash btn btn-white btn-bitbucket text-success" data-toggle="tooltip" data-placement="top" title="删除">
                                    <i class="fa fa-trash"></i>
                                </a>`)
                        }
                        return opers.join('');
                    }
                }],
                responseHandler: function (res) {console.log('res',res)
                    return {
                        total: res.page.totalCount,
                        rows: res.page.list
                    };
                },
                onLoadSuccess: function (data) {
                    $('[data-toggle="tooltip"]').tooltip()
                }
            });
        }
    })
</script>
</body>
</html>